package com.noble.glamour.ui.user.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.noble.glamour.R;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.util.UIShow;
import com.noble.glamour.third.recyclerholder.BaseRecyclerViewHolder;
import com.noble.glamour.ui.user.fragment.bean.UserAuth;
import com.noble.library.view.base.BasePanel;

import java.util.ArrayList;
import java.util.List;

/**
 * 个人中心的list布局panel
 */
public class UserFragmentFootPanel extends BasePanel implements BaseRecyclerViewHolder.OnItemClickListener {

    private RecyclerView recyclerView;
    private UserAuthAdapter userAuthAdapter;

    public UserFragmentFootPanel(Context context) {
        super(context);
        setContentView(R.layout.p1_user_fragment_footer);
        initData();
    }

    // 初始化条目数据
    private void initData() {
        List<UserAuth> userAuthList = new ArrayList<>();
        Resources resources = getContext().getResources();
        recyclerView = (RecyclerView) findViewById(R.id.user_fragment_footer);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setNestedScrollingEnabled(false); // 嵌套ScrollView滑动惯性消失
        String[] names = resources.getStringArray(R.array.user_authority_name);
        int[] levels = resources.getIntArray(R.array.user_authority_level);
        int[] icons = new int[]{R.drawable.user_wallet, R.drawable.user_wallet, R.drawable.user_diamond, R.drawable.user_gift, R.drawable.user_set, R.drawable.user_set, R.drawable.user_set};

        for (int i = 0; i < names.length; i++) {
            UserAuth userAuth = new UserAuth(i, icons[i], levels[i], names[i], isShow(i));
            userAuthList.add(userAuth);
        }
        userAuthAdapter = new UserAuthAdapter();
        userAuthAdapter.setList(userAuthList);
        recyclerView.setAdapter(userAuthAdapter);
        userAuthAdapter.setOnItemClickListener(this);
    }

    /**
     * 刷新list
     */
    public void refreshView() {
        userAuthAdapter.notifyDataSetChanged();
    }

    /**
     * 判断指定条目显隐状态
     */
    private boolean isShow(int id) {
        boolean isMan = ModuleMgr.getCenterMgr().getMyInfo().isMan();
        if (isMan && id == CenterItemID.i_Center_item_1) { // 男性用户隐藏：奖励计划
            return false;
        }
        return true;
    }

    @Override
    public void onItemClick(View convertView, int position) {
        switch (position) {
            case CenterItemID.i_Center_item_1:
                UIShow.showUserLevelAct(getContext());
                break;

            case CenterItemID.i_Center_item_2: // 我的钱包
                UIShow.showRedBoxRecordAct(getContext());
                break;

            case CenterItemID.i_Center_item_3:// 我的钻石
                UIShow.showMyDiamondsAct(getContext());
                break;

            case CenterItemID.i_Center_item_4:// 我的礼物
                UIShow.showMyGiftActivity(getContext());
                break;

            case CenterItemID.i_Center_item_5:// 相册
                UIShow.showUserPhotoAct(getContext());
                break;

            case CenterItemID.i_Center_item_6:// 资料
                UIShow.showUserEditInfoAct(getContext());
                break;

            case CenterItemID.i_Center_item_7:// 设置中心
                UIShow.showUserSetAct((Activity) getContext(), 100);
                break;
        }
    }
}
